package com.example.demo.controller;

import com.example.demo.common.ImageHandle;
import com.example.demo.common.R;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;


@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ImageHandle imageHandle;

    //获取登陆页面的图片验证码
    @GetMapping("/getPicCode")
    public R<User> getPicCode() throws IOException {
        User user= userMapper.selectOne(null);

        //验证码图片路径从数据库取出并加密后返回
        String imagePath = user.getImagePath();
        System.out.println(imagePath);
        user.setImagePath(imageHandle.getImageAsBase64(imagePath));

        return R.success(user);
    }

}
